package main

import (
	"log"
	"os"
	"strconv"
)

type Env struct {
	S Storage
}

//Redis环境变量读取
func getEnv() *Env {
	addr := os.Getenv("APP_REDIS_ADDR")// windows系统里设置的环境变量
	if addr == "" {
		addr = "localhost:6379"
	}
	passwd := os.Getenv("APP_REDIS_PASSWD")
	if passwd == "" {
		 passwd = ""
	}

	dbS := os.Getenv("APP_REDIS_DB")
	if dbS == "" {
		dbS = "0"
	}
	db, err := strconv.Atoi(dbS)
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("Connect to redis (addr: %s, password: %s db: %d)", addr, passwd, db)

	r := NewRedisCli(addr, passwd, db)
	return &Env{S: r}
}
